'use strict';

function countSameElements(collection) {
  let result=[];
  for(let i=0;i<collection.length;i++){
    let num=1;
    let object={};
    if(collection[i].length>1){
      num=parseInt(collection[i].replace(/[^0-9]/ig,"")) ;
      collection[i]=collection[i].substring(0,1);
    }
    for(let j=i+1;j<collection.length;j++){
      if(collection[j].length>1){
        if(collection[i]==collection[j].substring(0,1)){
          num=num+parseInt(collection[j].replace(/[^0-9]/ig,""));
          collection.splice(j,1);
          j--;
        }
      }
      else{
        if(collection[i]==collection[j]){
          num++;
          collection.splice(j,1);
          j--;
        }
      }
     }
     object.name=collection[i];
     object.summary=num;
     result.push(object);
  }
  console.log(result);
  return result;
}
module.exports =countSameElements
countSameElements([
  'a', 'a', 'a',
  'e', 'e', 'e', 'e', 'e', 'e', 'e',
  'h', 'h', 'h', 'h', 'h', 'h', 'h[3]', 'h', 'h',
  't', 't-2', 't', 't', 't', 't', 't', 't', 't[10]',
  'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f',
  'c:8',
  'g', 'g', 'g', 'g', 'g', 'g', 'g',
  'b', 'b', 'b', 'b', 'b', 'b',
  'd-5'
])